<!---
Name:        categories.cfm
Author:      Dmitry Svito (prostotelo@gmail.com)
Description: categories summary
Created:     25.03.2011
--->
<cfparam name="Categ" type="integer" default="0">
<cfparam name="Form.x" type="string" default="">

<!---Categories--->
<cfset CatObjGate = createObject("component", "Catalog.DataAccessLayer.CategoriesGateway").init() />
<cfset CategoriesAll = CatObjGate.getAll()>
<!---Products--->
<cfset ProdObjGate	= createObject("component", "Catalog.DataAccessLayer.ProductsGateway").init() />

<html>
<head>
	<title>
		Joe's Catalog
		Categories
	</title>
</head>
<body>
<a href="/catalog/businesslayer/index.cfm">Go to Catalog</a> |
<a href="/catalog/businesslayer/login.cfm">Relogin</a> |
<!---<cfoutput><a href="#AjaxLink("logout.cfm")#">Logout</a><br></cfoutput>--->
<a href="/catalog/businesslayer/logout.cfm">Logout</a><br>		

<table width="25%" border="0" cellspacing="2" cellpadding="2" summary="Categories">
    <caption align="top">
        <strong>Categories</strong>
    </caption>
<cfoutput>
	<cfform name="categoriesform">
		<cfloop array="#CategoriesAll#" index="Category">
			<cfset CategoryID = Category.getCategoryID()>
			<cfset CountOfCategory = ProdObjGate.countprodofcat(CategoryID)>
		    <tr>
		        <td width="85%">
					#Category.getCategoryName()#(#CountOfCategory#)
		        </td>
		        <td>
		        	<a href="addeditcateg.cfm?cat=#CategoryID#" target="_self">
		        		<img src="/catalog/images/pencil.jpg" alt="" width="16" height="16" title="Edit"/>
					</a>
		        </td>
		        <td>
					<cfinput type="image" name="x" src="/catalog/images/x.jpg" width="16" height="16" value="#CategoryID#">
		        </td>
		        <td>
		        	<a href="products.cfm?cat=#CategoryID#" target="_self">
		        		<img src="/catalog/images/arrow.jpg" alt="" width="16" height="16" title="View products"/>
					</a>
		        </td>
		    </tr>
		</cfloop>		
	</cfform>			
</cfoutput>
	<tr>
		<td colspan="4" align="center">
			<form name="catform" action="addeditcateg.cfm?add=1" method="post" accept-charset="utf-8">
				<input type="submit" value="Add">
			</form>
		</td>
	</tr>
</table>
<cfif Form.x IS NOT "">
	<cfset client.CategID = "#Form.x#">
	<cflocation url="delete.cfm?flag=c">
</cfif>
<cfif isDefined("client.delmes")>
	<cfset delornot = "#client.delmes#">
	<cfif delornot IS "true">
		<cfoutput>
			Category deleted.
		</cfoutput>
	</cfif>
	<cfset client.delmes = "false">
</cfif>
</body>
</html>